﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BBCP.Model;

namespace BBCP.UI.Tasks
{
    public class CountProducts : ITask
    {

        public bool Run()
        {
            try
            {

                using (NorthwindEntities context = new NorthwindEntities())
                {
                    var res = context.Products.OrderByDescending(n => n.Order_Details.Sum(m => m.Quantity));

                    foreach (var item in res)
                    {
                        Console.WriteLine("Product Name: {0} - {1}", item.ProductName, item.Order_Details.Sum(n => n.Quantity));
                    }
                }
            }
            catch (Exception)
            {
                
                return false;
            }
            return true;
        }
    }
}
